﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BaMusaSoft.RPS.DataModel;
using BaMusaSoft.RPS.RPSServices.Reports;
using BaMusaSoft.RPS.ViewModel;
using BaMusaSoft.RPS.ViewModel.Infrastructure;
using GalaSoft.MvvmLight.Command;

namespace BaMusaSoft.RPS.View
{
    /// <summary>
    /// Interaction logic for AllSchedulesView.xaml
    /// </summary>
    public partial class AllSchedulesView : UserControl
    {
        AllSchedulesViewModel _vm;
        #region "Fields"
        RelayCommand _editScheduleCommand;
        IUnitOfWork _session;
        #endregion
        public AllSchedulesView()
        {
            InitializeComponent();
        }

        private void ViewLoaded(object sender, RoutedEventArgs e)
        {
           _vm = (AllSchedulesViewModel)this.DataContext;
            //vm.ControlGridColumns += new EventHandler<NotificationEventArgs>(ControlGridColumns);
           
            _session = ((AllSchedulesViewModel)DataContext).UnitOfWork;
        }

        //void ControlGridColumns(object sender, NotificationEventArgs e)
        //{
        //    //DataGridColumnsViewModel d = new DataGridColumnsViewModel();
        //    //DataGridColumnsVisibilty columns = new DataGridColumnsVisibilty(d);
        //    //columns.ShowDialog();
        //}

        private void ViewUnloaded(object sender, RoutedEventArgs e)
        {
            //vm.ControlGridColumns -= new EventHandler<NotificationEventArgs>(ControlGridColumns);
            
        }
        #region "Commands"
        public ICommand EditScheduleCommand
        {
            get 
            {
                if (_editScheduleCommand == null)
                {
                    return _editScheduleCommand ?? (_editScheduleCommand = new RelayCommand(EditSchedule, CanEditSchedule));
                }
                return _editScheduleCommand;
            }
        }
        private void EditSchedule()
        {
            AllSchedulesReportFields selected = schedulesDataGrid.SelectedItem as AllSchedulesReportFields;
            if (selected != null)
            {
                string scheduleId = selected.ScheduleId;
                MainViewModel.Current.EditScheduleCommnad.Execute(scheduleId);

            }
            
        }
        private bool CanEditSchedule()
        {
           
            return schedulesDataGrid != null && schedulesDataGrid.SelectedItem != null;
        }
        #endregion

        
       
    }
}
